package de.hmm.hwip.configuration.spot;

import de.hmm.hwip.configuration.api.ISpotConf;

/**
 *  Pojo to get querys to get or set Data in spot configurations
 * 
 * @author Johannes Mendel
 * @version 01.10.2012
 *
 */
public class SpotImpl implements ISpotConf{

	/**
	 * function to get the query for getting all spotIds
	 * 
	 * @return query to get data
	 */
	@Override
	public String getQueryForSpotIds(){
		String query = "";
		
		query = "SELECT spot_id FROM spot;";
		
		return query;
	}
	
	/**
	 * function to get the query for getting spot data and roomid + description
	 * 
	 * @return query to get data
	 */
	@Override
	public String getQueryForSpots(){
		String query = "";
		
		//query = "SELECT s.spot_id, s.ip_adress, r.r_description, r.room_id FROM spot AS s , room AS r WHERE r.room_id = s.room_id_fk;";
		query = "SELECT spot_id, room_id_fk, ip_address FROM spot ;";
		
		return query;
	}
	
	/**
	 * function to get the query for setting a new spot to table
	 * 
	 * @param id: primary key of spot
	 * @param roomId: pk from room table
	 * @param ipAdress: IP Adress from Spot
	 * 
	 * @return query to set new spot
	 */
	@Override
	public String getQueryForSetSpot(int id, int roomId, String ipAddress){
		String query = "";
		
		query = "INSERT INTO spot (spot_id, room_id_fk, ip_address) VALUES (" + id +", "+ roomId + ", '" + ipAddress + "');";
		
		return query;
	}

	/**
	 * function to get the query for delete a spot by id
	 * 
	 * @param spotId: spot_id of the spot
	 * @return query to delete Spot
	 */
	@Override
	public String getQueryForDeleteSpot(int id) {
		String query = "";
		
		query = "DELETE FROM spot WHERE spot_id = "+ id +" ;";
		
		return query;
	}

	/**
	 * function to get the query for getting a spotId by ipAdress
	 * 
	 * @param ipAddress: ip_adress of the spot
	 * @return query to get Spot ID
	 */
	@Override
	public String getQueryForSpotId(String ipaddress) {
		String query = "";
		
		query = "SELECT spot_id FROM spot WHERE ip_address = '" + ipaddress + "' ;";
		
		return query;
	}

	/**
	 * function to get the query for updating spot in table
	 * 
	 * @param id: primary key of spot
	 * @param ip: ip adress of the Spot
	 * @param room_id: room_id_fk of room 
	 * 
	 * @return query to update spot entry
	 */
	@Override
	public String getQueryForUpdateSpot(int id, String ip, int room_id) {
		String query = ""; 
		
		query = "UPDATE spot SET " +
				"room_id_fk = " + room_id +
				" , ip_address = '" + ip  +
				"' WHERE spot_id = " + id + " ;";
		
		return query;
	}
}
